package valueobject

// SessionStatus 会话状态值对象
type SessionStatus int

const (
	// SessionStatusActive 活跃状态
	SessionStatusActive SessionStatus = iota
	// SessionStatusInactive 非活跃状态
	SessionStatusInactive
	// SessionStatusClosed 已关闭状态
	SessionStatusClosed
	// SessionStatusExpired 已过期状态
	SessionStatusExpired
)

// String 返回会话状态的字符串表示
func (s SessionStatus) String() string {
	switch s {
	case SessionStatusActive:
		return "Active"
	case SessionStatusInactive:
		return "Inactive"
	case SessionStatusClosed:
		return "Closed"
	case SessionStatusExpired:
		return "Expired"
	default:
		return "Unknown"
	}
}

// IsValid 判断会话状态是否有效
func (s SessionStatus) IsValid() bool {
	return s >= SessionStatusActive && s <= SessionStatusExpired
}

// CanTransitionTo 判断是否可以转换到目标状态
func (s SessionStatus) CanTransitionTo(target SessionStatus) bool {
	switch s {
	case SessionStatusActive:
		// 活跃状态可以转换到任何状态
		return true
	case SessionStatusInactive:
		// 非活跃状态可以转换到活跃、关闭或过期状态
		return target == SessionStatusActive || target == SessionStatusClosed || target == SessionStatusExpired
	case SessionStatusClosed:
		// 已关闭状态不能转换到其他状态
		return false
	case SessionStatusExpired:
		// 已过期状态不能转换到其他状态
		return false
	default:
		return false
	}
}